package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.OrderDetailCreateRequest;
import com.ruoyi.system.domain.UpdateStatusRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TCkOrderdetail;
import com.ruoyi.system.service.ITCkOrderdetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库物料明细
Controller
 *
 * @author ruoyi
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/system/ORDERDETAIL")
public class TCkOrderdetailController extends BaseController
{
    @Autowired
    private ITCkOrderdetailService tCkOrderdetailService;

    /**
     * 查询出库物料明细列表
     */
    /*@PreAuthorize("@ss.hasPermi('system:ORDERDETAIL:list')")*/
    @GetMapping("/list")
    public TableDataInfo list(TCkOrderdetail tCkOrderdetail)
    {
        startPage();
        List<TCkOrderdetail> list = tCkOrderdetailService.selectTCkOrderdetailList(tCkOrderdetail);
        return getDataTable(list);
    }

    /**
     * 导出出库物料明细
列表
     */
    @PreAuthorize("@ss.hasPermi('system:ORDERDETAIL:export')")
    @Log(title = "出库物料明细 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCkOrderdetail tCkOrderdetail)
    {
        List<TCkOrderdetail> list = tCkOrderdetailService.selectTCkOrderdetailList(tCkOrderdetail);
        ExcelUtil<TCkOrderdetail> util = new ExcelUtil<TCkOrderdetail>(TCkOrderdetail.class);
        util.exportExcel(response, list, "出库物料明细 数据");
    }

    /**
     * 获取出库物料明细
详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ORDERDETAIL:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return success(tCkOrderdetailService.selectTCkOrderdetailByOrderId(orderId));
    }

    /**
     * 新增出库物料明细

     */
    @PreAuthorize("@ss.hasPermi('system:ORDERDETAIL:add')")
    @Log(title = "出库物料明细 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCkOrderdetail tCkOrderdetail)
    {
        return toAjax(tCkOrderdetailService.insertTCkOrderdetail(tCkOrderdetail));
    }

    /**
     * 修改出库物料明细

     */
    @PreAuthorize("@ss.hasPermi('system:ORDERDETAIL:edit')")
    @Log(title = "出库物料明细 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCkOrderdetail tCkOrderdetail)
    {
        return toAjax(tCkOrderdetailService.updateTCkOrderdetail(tCkOrderdetail));
    }

    /**
     * 删除出库物料明细

     */
    @PreAuthorize("@ss.hasPermi('system:ORDERDETAIL:remove')")
    @Log(title = "出库物料明细 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(tCkOrderdetailService.deleteTCkOrderdetailByOrderIds(orderIds));
    }

    @PreAuthorize("@ss.hasPermi('system:ORDERDETAIL:create')")
    @Log(title = "创建物料明细 ", businessType = BusinessType.INSERT)
    // 控制器方法
    @PostMapping("/create")
    public AjaxResult creates(@RequestBody OrderDetailCreateRequest request) {
        // 使用request.getStockIds()和request.getValues()来处理数据
        int creates = tCkOrderdetailService.creates(request);
        return toAjax(creates);


    }

    @PostMapping("/updateCkSts")
    public AjaxResult updateCkSts(@RequestBody UpdateStatusRequest request) {
        return toAjax(tCkOrderdetailService.updateCkSts(request));
    }

    @GetMapping("/lists")
    public TableDataInfo lists(TCkOrderdetail tCkOrderdetail)
    {
        startPage();
        String[] addTimes = tCkOrderdetail.getAddTimes();
        if (addTimes != null && addTimes.length > 1) {
            tCkOrderdetail.setStartTime(addTimes[0]);
            tCkOrderdetail.setEndsTime(addTimes[1]);
        }
        List<TCkOrderdetail> list = tCkOrderdetailService.selectTCkOrderdetailLists(tCkOrderdetail);
        return getDataTable(list);
    }
}
